package java3_24;

import java.util.Scanner;

/**
 * 1:输入两个字符串，查找第一个字符串在第二个字符串中出现的次数
 * 比如输入dog和 This is a good dog.
 * 则出现了一次。
 */
public class StringHomework1 {
    public static void main(String[] args) {
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串:");
        String str1 = scanner.next();
        System.out.println("请输入要查找的字符串:");
        String str2 = scanner.next();
        if (!str1.contains(str2)){
            System.out.println("出现了0次！");
        }else {
            boolean flag = true;
            int x = 0;
            while (flag){
                x = str1.indexOf(str2,x);
                x=x+str2.length();
                if (x!=1) {
                    count++;
                }else {
                    flag = false;
                }
            }
        }
        System.out.println(str2+"一共出现了："+count+"次");
//        System.out.println("dog一共出现了"+x+"次");
    }
}
